<template>
	
	

	<div style="border: 1px solid #303133 ;">
		<div style="font-weight: 800; margin: 5px;">{{sku_info.spu_name}} id:{{sku_id}}</div>


		<van-row>
			<van-col span="8">
				<van-image style="" src="https://img01.yzcdn.cn/vant/ipad.jpeg" width="5rem" height="5rem"
					fit="contain">
					<template v-slot:error>加载失败</template>
				</van-image>

			</van-col>
			<van-col span="16">
				<div style="margin-top: 5px;">品牌：{{sku_info.brand_name}}</div>
				<div style="margin-top: 5px;"> 单位：{{sku_info.unit_name}}</div>
				<div style="margin-top: 5px;"> 库存总量：{{quantity}}</div>

			</van-col>
		</van-row>


		<div style="margin: 10px;">
			<div style="font-weight: 600;">属性：</div>
			<div v-for="attribute in sku_attribute" style="margin: 8px ;width: 160px;">
				{{attribute.attribute_key}} : {{attribute.attribute_value}}
			</div>

		</div>
		
		<div class="detail">
			
		</div>










	</div>




</template>

<script>
	import {
		Toast
	} from 'vant'

	import {
		// select_all_ancestor_url,
		// select_class_son_url,
		// select_all_spu_by_class_id_url,
		// select_all_sku_url,
		select_sku_attribute_url,
		// select_warehouse_location_url,
		// select_sum_sku_account_url
		select_sum_sku_account_url,
		select_sku_url

	} from "../../utils/setting.js"
	export default {
		name: '',
		components: {},
		props: [
			'skuId'
		],
		data() {
			return {
				sku_id: this.skuId,
				sku_attribute: null,
				sku_info: {},
				now_sku_quantity: null,
				goods_sum_list: [],
				quantity: 0,
				detail:[]
			}
		},
		methods: {


			//获得指定sku_id的属性
			get_sku_attribute(sku_id) {

				this.$axios({
					method: 'GET',
					url: select_sku_attribute_url,
					params: {
						sku_id: sku_id
					}
				}).then((response) => { //这里使用了ES6的语法
					// console.log(response) //请求成功返回的数据
					this.sku_attribute = response.data.resultBody.reverse()
					// console.log(this.sku_attribute)

				}).catch((error) => {
					console.log(error) //请求失败返回的数据
					this.$message({
						message: '请联系管理员' + '!!!',
						type: 'error'
					})
				})

			},


			//获得指定sku_id的信息
			get_sku_info(sku_id) {

				this.$axios({
					method: 'GET',
					url: select_sku_url,
					params: {
						sku_id: sku_id
					}
				}).then((response) => { //这里使用了ES6的语法
					// console.log(response) //请求成功返回的数据
					this.sku_info = response.data.resultBody.reverse()[0]
					// this.sku_name = sku_info
					// console.log(this.sku_info)

				}).catch((error) => {
					// console.log(error) //请求失败返回的数据
					this.$message({
						message: '请联系管理员' + '!!!',
						type: 'error'
					})
				})

			},


			//库存数量
			get_goods_sum() {

				// console.log(warehouse_id)
				this.goods_sum = []
				this.$axios({
					method: 'GET',
					url: select_sum_sku_account_url,

				}).then((response) => { //这里使用了ES6的语法
					// console.log(response) //请求成功返回的数据

					let val = response.data.resultBody.reverse()
					console.log(val)
					//入库例表
					let in_list = []
					let out_list = []

					for (let i = 0; i < val.length; i++) {
						if (val[i].in_or_out == true) {
							in_list.push(val[i])
						} else {
							out_list.push(val[i])
						}

					}

					for (let i = 0; i < in_list.length; i++) {

						// console.log(in_list[i].sku_id)

						for (let ii = 0; ii < out_list.length; ii++) {
							// console.log(in_list[i])
							// console.log(out_list[ii])

							if (in_list[i].sku_id == out_list[ii].sku_id) {
								in_list[i].sum = in_list[i].sum - out_list[ii].sum
								break
							}
						}

					}

					this.goods_sum_list = in_list
					// console.log(in_list)

					for (let i = 0; i < this.goods_sum_list.length; i++) {
						if (this.sku_id == this.goods_sum_list[i].sku_id) {
							this.quantity = this.goods_sum_list[i].sum
							break
						}
					}

				}).catch((error) => {
					console.log(error) //请求失败返回的数据
					this.$message({
						message: '请联系管理员--' + '!!!',
						type: 'error'
					})
				})

			},

		},
		computed: {},
		watch: {},
		created() {},
		mounted() {

			this.get_sku_info(this.sku_id)

			this.get_sku_attribute(this.sku_id)

			this.get_goods_sum()

		},
	}
</script>

<style scoped lang="less">

</style>
